﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Diagnostics;
using System.Reflection;
using Fulcrum.DispatcherProxies;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.DispatcherProxies
{
    [TestClass]
    public class DispatcherProxyMethodInfoTests
    {
        public DispatcherProxyMethodInfoTests()
        {
            // nothign
        }

        MethodInfo methodInfo;
        DispatcherProxyMethodInfo proxyMethodInfo;

        [TestInitialize]
        public void TestInitalize()
        {
            this.methodInfo = GetMethodInfo("MyMethod");
            this.proxyMethodInfo = new DispatcherProxyMethodInfo(this.methodInfo, true);
        }

        MethodInfo GetMethodInfo(string methodName)
        {
            var type = this.GetType();
            var method = type.GetMethod(methodName);

            Debug.Assert(method != null);

            return method;
        }

        public int MyMethod()
        {
            throw new NotImplementedException();
        }

        [TestMethod]
        public void TestDispatcherProxyMethodInfoIsNew()
        {
            Assert.IsTrue(this.proxyMethodInfo.IsNew);
        }

        [TestMethod]
        public void TestDispatcherProxyMethodInfoMethod()
        {
            Assert.AreSame(this.methodInfo, this.proxyMethodInfo.Method);
        }

        [TestMethod]
        public void TestDispatcherProxyMethodInfoObsoleteAttribute()
        {
            Assert.IsNull(this.proxyMethodInfo.ObsoleteAttribute);
        }

        [TestMethod]
        public void TestDispatcherProxyMethodInfoRequiresOverride()
        {
            Assert.IsFalse(this.proxyMethodInfo.RequiresOverride);
        }

        [TestMethod]
        public void TestDispatcherProxyMethodInfoRequiresOverrideEquals()
        {
            var proxyMethodInfo = CreateProxyMethodInfo("Equals");

            Assert.IsTrue(proxyMethodInfo.RequiresOverride);
        }

        private DispatcherProxyMethodInfo CreateProxyMethodInfo(string methodName)
        {
            var methodInfo = GetMethodInfo(methodName);
            var proxyMethodInfo = new DispatcherProxyMethodInfo(methodInfo, true);
            return proxyMethodInfo;
        }

        [TestMethod]
        public void TestDispatcherProxyMethodInfoRequiresOverrideGetHashCode()
        {
            var proxyMethodInfo = CreateProxyMethodInfo("GetHashCode");

            Assert.IsTrue(proxyMethodInfo.RequiresOverride);
        }

        [TestMethod]
        public void TestDispatcherProxyMethodInfoRequiresOverrideToString()
        {
            var proxyMethodInfo = CreateProxyMethodInfo("ToString");

            Assert.IsTrue(proxyMethodInfo.RequiresOverride);
        }

    }
}
